import React, { Component } from 'react';
import { StyleSheet, Text, Dimensions, TouchableOpacity } from "react-native";
import { style } from '../theme/style';

const ScreenWidth = Dimensions.get('window').width;
const scale = ScreenWidth / 375;

export class CodeEndCpt extends Component {
	constructor(props) {
		super(props);
		this.state = {
			code: 60
		}
		this._setCode = this._setCode.bind(this);
	}
	_setCode () {
		var timer = null;
		timer = setInterval(() => {
			if (!this.state.code) {
				clearInterval(timer);
				this.props._getData({ onoff: true });
				// Alert.alert('', '验证码已过期，请重新获取', [
				// 	{ text: '确认', onPress: () => { this.props._getData({ onoff: true }) } }
				// ]);
			} else {
				this.setState({
					code: --this.state.code
				})
			}
		}, 1000);
	}
	componentDidMount () { //render
		this._setCode();
	}
	render () {
		return (
			<TouchableOpacity style={styles.commitYzmBoxSend}>
				<Text style={styles.commitYzmSend}>已发送({this.state.code}s)</Text>
			</TouchableOpacity>
		)
	}
}

const styles = StyleSheet.create({
	commitYzmBoxSend: {
		alignSelf: 'center',
		padding: 6 * scale,
		borderRadius: 13 * scale,
		borderWidth: style.color.darkGray,
		borderWidth: 1,
		borderStyle: 'solid',
		justifyContent: 'center',
		alignItems: 'center'
	},
	commitYzm: {
		color: style.color.white,
		fontSize: 13 * scale
	}
})